import requests
from config import url, headers_web, headers_wechat


class LearningTest:
    def __init__(self):
        self.url = url
        self.headers = headers_web, headers_wechat

    @classmethod
    def post_add_learning_test(cls, url_path: str, headers=headers_web, params=None, json=None):
        """
        @summary:创建学情测验
        @description:创建学情测验，云课堂老师端使用
        :param url_path:/teachingApi/v1/learningtest
        :param headers:Content-Type:application/json
        :param params:validCode:加密验证码&signKey=123123
        :param json:{
                    "testRequireType": 0,
                    "courseCode": "", # 课程编码
                    "creatorId": "", # 创建人ID
                    "creatorName": "", # 创建人姓名
                    "collegeCode": "", # 课程学院编码
                    "termId": "", # 学年学期ID
                    "collegeId": "",# 课程学院ID
                    "fillElectionScore": 0, # 填空提分数
                    "schoolYear": "", # 学年
                    "startTime": "", #  开始时间
                    "term": 0, # 学期
                    "id": "", # 学情测验ID
                    "courseId": "", # 课程ID
                    "classList": [{ # 学情测验发布班级列表
                        "classId": "", # 班级id
                        "classNo": "", # 班级编号
                        "className": "" # 班级名称
                        }],
                    "scoreSetting": 0, # 分值设置(0:不设置分值，1：设置分值)
                    "creatorNo": "",# 创建人工号
                    "multipleElectionScore": 0, # 多选题分数
                    "testPaperId": "", # 测验试卷id
                    "structureId": "", # 所属章节id
                    "totalScore": 0, # 总分
                    "testTitle": "", # 测验标题
                    "collegeName": "", #课程学院名称
                    "courseName": "", # 课程名称
                    "judgeElectionScore": 0, # 判断题分数
                    "singleElectionScore": 0,# 多选题分数
                    "endTime": "" # 测验结束时间
                    }
        :return:
        """
        url_path = url_path + "/teachingApi/v1/learningtest"
        r = requests.post(url=url_path, params=params, json=json, headers=headers)
        return r

    @classmethod
    def get_teacher_query_learning_test_question_options(cls, url_path: str, headers=headers_web, params=None,
                                                         params_path=None):
        """
        @summary:老师查看学情测验活动题目选项选择人数
        @description:老师查看学情测验活动题目选项选择人数
        :param params_path: id:学情测验题目选项id
        :param url_path:/teachingApi/v1/learningtest/learningtestquestionoption/{id}
        :param headers:
        :param params:validCode:验证码（id=?&signKey=123123）
        :return:object:{
                        "innerAvatarUrl":"", # 内网头像地址
                        "outerAvatarUrl":"", # 外网头像地址
                        "studentName":"", # 学生姓名
                        "studentNo":"" # 学生学号
                        }
        """
        url_path = url_path + "/teachingApi/v1/learningtest/learningtestquestionoption/{}".format(params_path)
        r = requests.get(url=url_path, params=params, headers=headers)
        return r

    @classmethod
    def post_student_submit_test_wechat(cls, url_path: str, headers=headers_wechat, params=None, json=None):
        """
        @summary:小程序学生提交学情测验
        @description:小程序学生提交学情测验
        :param url_path:
        :param headers:Content-Type:application/json
        :param params:{
                        "groupId":"", # 班级id
                        "id":"", # 学生id
                        "testid":"", # 测试id
                        "validCode":"" # 验证码：id=?&signKey=123123(md5加密)
                        }
        :param json:
        :return:{
                "innerAvatarUrl":"", # 内网头像地址
                "outerAvatarUrl":"", # 外网头像地址
                "studentCollegeId":"", # 答题学生学院Id
                "studentCollegeName":"", # 答题学生学院名称
                "studentGrade":"", # 答题学生年级
                "studentId":"", # 学生id
                "studentName":"", # 学生姓名
                "studentNo":"", # 学号
                "questionList":[{
                    "id":"", # 题目id
                    "optionIds":"",# 选择的选项id，使用逗号隔开
                    "fillVacantModelList":{
                        "answerContent":"", # 答案内容
                        "questionOptionId":"" # 问题选项Id
                        }
                    }]
                }
        """
        url_path = url_path + "/teachingApi/v1/learningtest/student"
        r = requests.post(url=url_path, params=params, headers=headers, json=json)
        return r

    @classmethod
    def get_learning_test_detail(cls, url_path: str, headers=headers_web, params=None, params_path=None):
        """
        @summary:云课堂老师端获取学情测验详细信息
        @description:云课堂老师端获取学情测验详细信息
        :param url_path:/teachingApi/v1/learningtest/{id}/learningtestdata
        :param headers:
        :param params:validCode:验证码：id=?&signKey=123123(md5加密)
        :param params_path:id:学情测验id
        :return:
        """
        url_path = url_path + "/teachingApi/v1/learningtest/{}/learningtestdata".format(params_path)
        r = requests.get(url=url_path, params=params, headers=headers)
        return r

    @classmethod
    def get_detail_question(cls, url_path: str, headers=headers_web, params=None, params_path=None):
        """
        @summary:老师查看学情测验活动试题分析
        @description:老师查看学情测验活动试题分析
        :param url_path:/teachingApi/v1/learningtest/{id}/question
        :param headers:
        :param params:{
                        "page":"",# 当前页
                        "pageSize":"",# 每页个数
                        "validCode":"" # 验证码（id=?&signKey=123123）
                        }

        :param params_path:id:学情测验活动id
        :return:{
                    "page":"",# 当前页
                    "pageSize":"",# 每页个数
                    "pageCount":"", # 总页数
                    "total":"", # 总条数
                    "learningTestQuestionsResource":{
                        "correctRate":"", # 正确率
                        "questionTypeName":"", # 题目类型名称
                        "showOrder":"" # 序号
                        }
                    }
        """
        url_path = url_path + "/teachingApi/v1/learningtest/{}/question".format(params_path)
        r = requests.get(url=url_path, params=params, headers=headers)
        return r

    @classmethod
    def get_learning_test_question_statistics(cls, url_path: str, headers=headers_web, params=None, params_path=None):
        """
        @summary:老师查看学情测验活动题目
        @description:老师查看学情测验活动试题分析详情
        :param url_path:/teachingApi/v1/learningtest/{id}/questionStatistics
        :param headers:
        :param params:validCode:验证码（id=?&signKey=123123）
        :param params_path:id:学情测验活动id
        :return:
        """
        url_path = url_path + "/teachingApi/v1/learningtest/{}/questionStatistics".format(params_path)
        r = requests.get(url=url_path, params=params, headers=headers)
        return r

    @classmethod
    def get_finsh_statistics(cls, url_path: str, headers=headers_web, params=None, params_path=None):
        """
        @summary:老师查看已完成的学情测验统计
        @description:web老师端查看学情测验详情中学情测验统计调用
        :param url_path:
        :param headers:
        :param params:validCode:验证码（id={}&signKey=123123）
        :param params_path:id:学情测验id
        :return:{
                "allCount":"", # 总人数
                "answerCount":"", # 已提交人数
                "averageAccuracy":"",# 平均正确率
                "belowSixtyPercent":"",# 正确率60%一下
                "eightytoHundredPercent":"",#正确率率80-100
                "notAnswerCount":"",# 未提交人数
                "sixtytoEightyPercent":"", # 正确率60-80
                "questionList":[{ # 题目正确率
                    "correctRate":"", # 正确率
                    "questionNo":"" # 题目序号
                    }]
                }
        """

        url_path = url_path + "/teachingApi/v1/learningtest/{}/statistics".format(params_path)
        r = requests.get(url=url_path, params=params, headers=headers)
        return r

    @classmethod
    def post_modify_status(cls, url_path: str, headers=headers_web, params=None, params_path=None,json=None):
        """
        @summary:更改学情测验状态
        @description:云课堂老师端更改学情测验状态
        :param url_path:
        :param headers:Content-Type:application/json
        :param params:validCode:验证码（id={}&signKey=123123）
        :param params_path:id:学情测验id
        :param json:body:{
                        "modifierId":"",# 修改人id
                        "modifierName":"",# 修改人姓名
                        "modifierNo":"",# 修改人工号
                        "status":"" # 修改状态：0：未开始；1：进行中；2：已结束；3：已删除
                        }
        :return:ok
        """
        url_path = url_path + "/teachingApi/v1/learningtest/{}/status".format(params_path)
        r = requests.post(url=url_path, params=params, headers=headers,json=json)
        return r

    @classmethod
    def get_query_student_list(cls, url_path: str, headers=headers_web, params=None, params_path=None):
        """
        @summary:老师查看学生学情测验列表
        @description:web老师端查看学情测验详情中学生表现调用
        :param url_path:/teachingApi/v1/learningtest/{id}/students
        :param headers:Content-Type:application/json
        :param params:{
                        "answerStatus":"", # 答题状态  0：全部；1：已提交；2：未提交
                        "userNoOrName":"", # 学生工号或姓名
                        "validCode":"" # 验证码（id={}&signKey=123123）
                        }
        :param params_path:id:学情测验id
        :return:
        """

        url_path = url_path + "/teachingApi/v1/learningtest/{}/students".format(params_path)
        r = requests.get(url=url_path, params=params, headers=headers)
        return r

    @classmethod
    def get_test_detail(cls, url_path: str, headers=headers_web, params=None):
        """
        @summary:老师查看学生学情测验列表
        @description:web老师端查看学情测验详情中学生表现调用
        :param url_path:/teachingApi/v1/learningtestdetail/student
        :param headers:
        :param params:{
                        "groupId":"", # 班级id
                        "id":"", # 学生id
                        "testid":"", # 测验id
                        "validCode":"" # 验证码：id=?&signKey=123123(md5加密)
                        }
        :return:
        """
        url_path = url_path + "/teachingApi/v1/learningtestdetail/student"
        r = requests.get(url=url_path, params=params, headers=headers)
        return r

    @classmethod
    def get_student_learning_list(cls, url_path: str, headers=headers_web, params=None, params_path=None):
        """
        @summary:获取学生学情测验活动列表
        @description:小程序获取学情测验活动列表
        :param url_path:/teachingApi/v1/student/{id}/learningtest
        :param headers:
        :param params:{
                        "courseId":"",#课程id
                        "groupIds":"",#教学班id集合（逗号分割）
                        "validCode":"" # 验证码：id=?&signKey=123123(md5加密)
                        }
        :param params_path:id:学生id
        :return:
        """
        url_path = url_path + "/teachingApi/v1/student/{}/learningtest".format(params_path)
        r = requests.get(url=url_path, params=params, headers=headers)
        return r

    @classmethod
    def get_all_list(cls, url_path: str, headers=headers_web, params=None):
        """
        @summary:获取测验活动列表
        @description:小程序老师端获取测验活动列表
        :param url_path:
        :param headers:
        :param params:{
                        "courseId":"",#课程id
                        "groupIds":"",#教学班id集合（逗号分割）
                        "validCode":"" # 验证码：id=?&signKey=123123(md5加密)
                        }
        :param params_path:id:学生id
        :return:
        """
        url_path = url_path + "/teachingApi/v1/teacher/learningtest"
        r = requests.get(url=url_path, params=params, headers=headers)
        return r

    @classmethod
    def get_all_detail(cls, url_path: str, headers=headers_web, params=None):
        """
        @summary:获取测验活动详情
        @description:小程序老师端获取测验活动详情
        :param url_path:/teachingApi/v1/teacher/learningtestdetail
        :param headers:
        :param params:{
                        "id":"", # 测验活动id
                        "validCode":"" # 验证码：id=?&signKey=123123(md5加密)
                        }
        :return:
        """
        url_path = url_path + "/teachingApi/v1/teacher/learningtestdetail"
        r = requests.get(url=url_path, params=params, headers=headers)
        return r

    @classmethod
    def get_student_learning_requirements(cls, url_path: str, headers=headers_web, params=None, params_path=None):
        """
        @summary:获取学生学情测验测试要求
        @description:小程序获取学情测验活动测试要求
        :param url_path:/teachingApi/v1/student/{id}/learningtest/testrequires
        :param headers:
        :param params:{
                        "groupIds":"", # 学生组ids
                        "learningTestId":"", # 学情测验id
                        "validCode":"" # 验证码：id=?&signKey=123123(md5加密)
                        }
        :param params_path:id:学生id
        :return:
        """

        url_path = url_path + "/teachingApi/v1/student/{}/learningtest/testrequires".format(params_path)
        r = requests.get(url=url_path, params=params, headers=headers)
        return r

    @classmethod
    def post_sumbit_answer_for_no(cls, url_path: str, headers=headers_web, params=None,json=None):
        """
        @summary:获取学生学情测验测试要求
        @description:小程序获取学情测验活动测试要求
        :param url_path:/teachingApi/v1/student/learningTest/submitByQuestionNo
        :param headers:headers_web
        :param params:validCode:验证码：&signKey=123123(md5加密)
        :param json:{
                    "checkedOptionIds":"",#选择的选项ID，多个使用逗号隔开
                    "groupId":"",#班级ID
                    "innerAvatarUrl":"",#内网头像地址
                    "isFinalCommitted":"",#是否为最终提交
                    "learningTestId":"",#学情测验ID
                    "outerAvatarUrl":"",#外网头像地址
                    "questionId":"",#题目ID
                    "studentCollegeId":"",#答题学生学院Id
                    "studentCollegeName":"",#答题学生学院名称
                    "studentGrade":"",#答题学生年级
                    "studentId":"",#学生id
                    "studentName":"",#学生姓名
                    "studentNo":"",#学号
                    "fillVacantModelList":[{
                        "answerContent":"",#答案内容
                        "questionOptionId":""#问题选项Id
                        }]
                    }
        :return:ok
        """
        url_path = url_path + "/teachingApi/v1/student/learningTest/submitByQuestionNo"
        r = requests.post(url=url_path, params=params, headers=headers,json=json)
        return r

    @classmethod
    def get_query_student_answer_status(cls, url_path: str, headers=headers_web, params=None,params_path=None):
        """
        @summary:接口-查询学情测验学生答题状态信息
        @description:接口-查询学情测验学生答题状态信息
        :param url_path:/teachingApi/v1/learningtest/{learningTestId}/studentanswerstatus
        :param headers:
        :param params:{
                        "groupId":"",# 班级id
                        "userId":"",#学生用户id
                        "validCode":""#learningTestId=?&signKey=123123
                        }
        :param params_path:learningTestId:学情测验id
        :return:{
                "answerStatus":"",
                "courseStructureId":"",
                "courseStructureName":"",
                "groupId":"",
                "learningTestId":"",
                "learningTestStatus":"",
                "needWatchVideo":"",
                "userId":""
                }
        """
        url_path = url_path + "/teachingApi/v1/learningtest/{}/studentanswerstatus".format(params_path)
        r = requests.get(url=url_path, params=params, headers=headers)
        return r

    @classmethod
    def post_urged_student(cls, url_path: str, headers=headers_web, params=None,params_path=None,json=None):
        """
        @summary:接口-催交测验，催交所有未提交测验的学生
        @description:云课堂老师端教学内容列表催交学情测验，催交所有未提交测验的学生使用
        :param url_path:
        :param headers:
        :param params:validCode:验证码：id={id}&signKey=123123(md5加密)
        :param params_path:id:测验id
        :param json:None
        :return:ok
        """
        url_path = url_path + "/teachingApi/v1/learningtest/{}/sendmessage".format(params_path)
        r = requests.get(url=url_path, params=params, headers=headers,json=json)
        return r

